<?php
header('Content-type: application/vnd.ms-excel');
header("Content-Disposition: attachment; filename=reporteInconsistencias.xls");
header("Pragma: no-cache");
header("Expires: 0");
require_once "../funciones.php";
$con = con_caweb();
$sql = "select distinct nit from equiposinconsistentes order by nit";
$result = mysql_query($sql);
echo "<table border = 1>";
echo "<tr>";
echo "<th>EMPRESA</th>";
echo "<th>NIT</th>";
echo "<th>INTERNO</th>";
echo "<th>ITEM</th>";
echo "<th>DESCRIPCION</th>";
echo "<th>TARIFA FACTURACION</th>";
echo "<th>TARIFA SERIALES</th>";
echo "<th>FECHA ENVIO</th>";
echo "<th>ENVIADO POR</th>";
echo "<th>NUMERO</th>";
echo "<th>SUCURSAL DE CREACION</th>";
echo "<th>SUCURSAL QUE FACTURA</th>";

echo "</tr>";
while ($cliente = mysql_fetch_array($result)) {
    //capturo el nombre del cliente
    $con = con_caweb();
    $sql = "select name from clientes where nit = '{$cliente['nit']}'";
    $tmp = mysql_query($sql);
    $nombre = mysql_fetch_array($tmp);
    //escribe informacion en el archivo
    $con = con_caweb();
    $sql = "select * from equiposinconsistentes where nit = '{$cliente['nit']}'";
    $select = mysql_query($sql);
    while ($fila = mysql_fetch_array($select)) {
        echo "<tr>";
        echo "<td>{$nombre['name']}</td>";
        echo "<td>{$fila['nit']}</td>";
        echo "<td>{$fila['interno']}</td>";
        echo "<td>{$fila['item']}</td>";
        echo "<td>{$fila['descripcion']}</td>";
        echo "<td>{$fila['tarifaFac']}</td>";
        echo "<td>{$fila['tarifaSer']}</td>";
        $sql = "select documentoref,numeroref,fechacreo,sucursal,sucursalfactura from cabeceras where transaccion = {$fila['transaccion']}";
        $cabe = mysql_query($sql);
        $cabe = mysql_fetch_array($cabe);
        echo "<td>{$cabe['fechacreo']}</td>";
        $sql = "select nombre from documentos where documento = '{$cabe['documentoref']}'";
        $tmp = mysql_query($sql);
        $tmp = mysql_fetch_array($tmp);
        echo "<td>{$tmp['nombre']}</td>";
        echo "<td>{$cabe['numeroref']}</td>";
        echo "<td>{$cabe['sucursal']}</td>";
        echo "<td>{$cabe['sucursalfactura']}</td>";
        echo "</tr>";
    }
}
echo "</table>";
?>
